//
//  STSmailFaceViewController.m
//  BasicAnimation-OC
//
//  Created by Stan on 2017-02-13.
//  Copyright © 2017 stan. All rights reserved.
//

#import "STSmailFaceViewController.h"

@interface STSmailFaceViewController ()
@property (weak, nonatomic) IBOutlet UIView *yellowView;
@property (weak, nonatomic) IBOutlet UIView *greenView;

@property (weak, nonatomic) IBOutlet UIView *mouseView;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation STSmailFaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置头部标题的文字
    self.titleLabel.text = @"吓死宝宝了！";
    
    //暂时先隐藏头部标题，等动画播放完成再显示
    [self.titleLabel setHidden:YES];
}

//    触摸屏之后触发的方法
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    __weak typeof(self) weakSelf = self;
    

    
    //添加阻尼动画
    [UIView animateWithDuration:0.8 delay:0.2 usingSpringWithDamping:0.6 initialSpringVelocity:0.8 options:UIViewAnimationOptionTransitionNone animations:^{
        
        
        //改变黄色的中心点位置
        
        weakSelf.yellowView.center = CGPointMake(weakSelf.view.bounds.size.width - weakSelf.yellowView.center.x, weakSelf.yellowView.center.y + 30);
        
        
        //改变蓝色的中心点位置
        weakSelf.greenView.center = CGPointMake(weakSelf.view.bounds.size.width - weakSelf.greenView.center.x, weakSelf.greenView.center.y + 30);
        
        //改变嘴巴的高度和中心点y的位置
        CGRect frame = CGRectMake(weakSelf.mouseView.frame.origin.x, weakSelf.mouseView.frame.origin.y, weakSelf.mouseView.frame.size.width, 180);
        
        weakSelf.mouseView.frame = frame;
        
        //这句一定要加，不然看不到动画
        [weakSelf.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        
        //添加阻尼动画
        
        [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0.8 options:UIViewAnimationOptionTransitionNone animations:^{
            //把隐藏的标题文字设置为显示状态
            [weakSelf.titleLabel setHidden:NO];
        } completion:nil];
    }];
    
}



@end
